package com.haochang.chunkvod.controller.activity.cash;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import com.haochang.base.BaseActivity;
import com.haochang.base.BaseTextView;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.app.utils.SaleUtils;
import com.haochang.chunkvod.model.cash.VehicleData;
import com.haochang.chunkvod.view.vod.popupWindow.VodPopWindow;
import com.haochang.chunkvod.view.vod.title.TitleView;

import android.os.Bundle;
import android.widget.ImageView;

/**
 *@author qintao
 *created at 2016/7/26 12:13
 * 交班详情
 */

public class ShiftDetailsActivity extends BaseActivity
{
	private TitleView titleView;
	private BaseTextView tv_operateDate;
	private BaseTextView tv_vehicle;
	private BaseTextView tv_vehicleNum;
	private BaseTextView tv_total;
	private BaseTextView tv_original;
	private BaseTextView tv_roomFee, tv_foodFee, tv_serviceFee, tv_otherFee;
	private BaseTextView tv_receivable;
	private BaseTextView tv_originalCount, tv_presentCount, tv_cutCount;
	private BaseTextView tv_pend;
	private BaseTextView tv_received;
	private BaseTextView tv_cash, tv_swipingCard, tv_weiXin, tv_aliPay, tv_signBill, tv_free, tv_reception, tv_pendCount, tv_balance;
	private VehicleData vehicleData;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
	}

	@Override
	public void receiveParam()
	{

	}

	@Override
	public void initData()
	{
		vehicleData = new VehicleData(ShiftDetailsActivity.this);
	}

	@Override
	public void initViews()
	{
		setContentView(R.layout.activity_shift_details);
		titleView = (TitleView) findViewById(R.id.titleView);
		titleView.setTitle("交班详情").setTitleOnClickListener(new TitleView.ITitleOnClickListener()
		{
			@Override
			public void onBackClick()
			{
				finish();
			}

			@Override
			public void onDoneClick()
			{
				List<String> list = new ArrayList<String>();
				list.add("退出登录");
				int location[] = new int[2];
				ImageView img = (ImageView) titleView.findViewById(R.id.img_operates);
				img.getLocationOnScreen(location);
				int x = location[0];
				final VodPopWindow pop = new VodPopWindow(ShiftDetailsActivity.this, list);
				pop.showPopupWindow(titleView, x);
				pop.setPopWindowListListener(new VodPopWindow.OnPopWindowListListener()
				{
					@Override
					public void onSelectItem(int position)
					{
						switch (position)
						{
						case 0:
							loginOut();
							break;
						default:
							break;
						}
					}
				});
			}
		});
		tv_operateDate = (BaseTextView) findViewById(R.id.tv_operateDate);
		tv_vehicle = (BaseTextView) findViewById(R.id.tv_vehicle);
		tv_vehicleNum = (BaseTextView) findViewById(R.id.tv_vehicleNum);
		tv_total = (BaseTextView) findViewById(R.id.tv_total);
		tv_original = (BaseTextView) findViewById(R.id.tv_original);
		tv_roomFee = (BaseTextView) findViewById(R.id.tv_roomFee);
		tv_foodFee = (BaseTextView) findViewById(R.id.tv_foodFee);
		tv_serviceFee = (BaseTextView) findViewById(R.id.tv_serviceFee);
		tv_otherFee = (BaseTextView) findViewById(R.id.tv_otherFee);
		tv_receivable = (BaseTextView) findViewById(R.id.tv_receivable);
		tv_originalCount = (BaseTextView) findViewById(R.id.tv_originalCount);
		tv_presentCount = (BaseTextView) findViewById(R.id.tv_presentCount);
		tv_cutCount = (BaseTextView) findViewById(R.id.tv_cutCount);
		tv_pend = (BaseTextView) findViewById(R.id.tv_pend);
		tv_received = (BaseTextView) findViewById(R.id.tv_received);
		tv_cash = (BaseTextView) findViewById(R.id.tv_cash);
		tv_swipingCard = (BaseTextView) findViewById(R.id.tv_swipingCard);
		tv_weiXin = (BaseTextView) findViewById(R.id.tv_weiXin);
		tv_aliPay = (BaseTextView) findViewById(R.id.tv_aliPay);
		tv_signBill = (BaseTextView) findViewById(R.id.tv_signBill);
		tv_free = (BaseTextView) findViewById(R.id.tv_free);
		tv_reception = (BaseTextView) findViewById(R.id.tv_reception);
		tv_pendCount = (BaseTextView) findViewById(R.id.tv_pendCount);
		tv_balance = (BaseTextView) findViewById(R.id.tv_balance);
		vehicleData.requestShiftDetails(new VehicleData.IShiftDetailsListener()
		{
			@Override
			public void onRequestSuccess(JSONObject jsonObject)
			{
				if (jsonObject != null)
				{
					tv_operateDate.setText(String.format("营业时间：%s", jsonObject.optString("bussiness_date")));
					tv_vehicle.setText(String.format("班次：%s", jsonObject.optString("shift")));
					tv_vehicleNum.setText(String.format("共%d班", jsonObject.optInt("shift_count")));
					tv_total.setText(jsonObject.optInt("bill_count") + "单");
					tv_original.setText(SaleUtils.getSaleString(jsonObject.optInt("original_fee")));
					tv_roomFee.setText(String.format("房费：%s", SaleUtils.getSaleString(jsonObject.optInt("room_fee"))));
					tv_foodFee.setText(String.format("餐饮费：%s", SaleUtils.getSaleString(jsonObject.optInt("food_fee"))));
					tv_serviceFee.setText(String.format("服务费：%s", SaleUtils.getSaleString(jsonObject.optInt("service_fee"))));
					tv_otherFee.setText(String.format("其他：%s", SaleUtils.getSaleString(jsonObject.optInt("other_fee"))));
					tv_receivable.setText(SaleUtils.getSaleString(jsonObject.optInt("receivable_fee")));
					tv_originalCount.setText(String.format("原始金额：%s", SaleUtils.getSaleString(jsonObject.optInt("original_fee"))));
					tv_presentCount.setText(String.format("增送金额：%s",
							jsonObject.optInt("present_fee") == 0 ? "0" : "-" + SaleUtils.getSaleString(jsonObject.optInt("present_fee"))));
					tv_cutCount.setText(String.format("扣款：%s",
							jsonObject.optInt("allowance_fee") == 0 ? "0" : "-" + SaleUtils.getSaleString(jsonObject.optInt("allowance_fee"))));
					tv_pend.setText(SaleUtils.getSaleString(jsonObject.optInt("guadan_fee")));
					tv_received.setText(SaleUtils.getSaleString(jsonObject.optInt("paied_fee")));
					tv_cash.setText(String.format("现金：%s", SaleUtils.getSaleString(jsonObject.optInt("cash_paied_fee"))));
					tv_swipingCard.setText(String.format("刷卡：%s", SaleUtils.getSaleString(jsonObject.optInt("card_paied_fee"))));
					tv_weiXin.setText(String.format("微信：%s", SaleUtils.getSaleString(jsonObject.optInt("weixin_paied_fee"))));
					tv_aliPay.setText(String.format("支付宝：%s", SaleUtils.getSaleString(jsonObject.optInt("alipay_paied_fee"))));
					tv_signBill.setText(String.format("签单：%s", SaleUtils.getSaleString(jsonObject.optInt("sign_paied_fee"))));
					tv_free.setText(String.format("免单：%s", SaleUtils.getSaleString(jsonObject.optInt("free_paied_fee"))));
					tv_reception.setText(String.format("招待：%s", SaleUtils.getSaleString(jsonObject.optInt("zhaodai_paied_fee"))));
					tv_pendCount.setText(String.format("挂账：%s", SaleUtils.getSaleString(jsonObject.optInt("guazhang_paied_fee"))));
					tv_balance.setText(String.format("余额：%s", SaleUtils.getSaleString(jsonObject.optInt("balance_paied_fee"))));
				}
			}
		});
	}
}
